**# Preample 
clear all
cd "INSERTPATH" 								// Remember to update file directory ("INSERTPATH")

set scheme plotplain

**# App. D.3
use  "data_S3.dta", clear 						// Remember to update file directory ("INSERTPATH") in cd above

* Covariate balance
gen strong_pid = 0 
replace strong_pid = 1 if pid == 2
gen mod_pid = 0 
replace mod_pid = 1 if pid == 1

gen female = 0 
replace female = 1 if gender == 1


foreach var in female P strong_pid mod_pid age {
	ttest `var',  by(D) unequal	
}

* Treatment recall (remember news source): 
tab recall									// 69.1 % correctly recall

reg recall i.D##i.M i.P, rob
reg recall i.D i.M i.P, rob


* ATET on electoral legitimacy 
gen election = (pei-1)/4

reg election i.D, rob
reg election i.D i.M i.P, rob


**# App. E.3
use  "data_S3.dta", clear 						// Remember to update file directory ("INSERTPATH") in cd above

gen election = (pei-1)/4
gen affect_inparty = (inparty_affect/10)
gen affect_outparty = (outparty_affect/10)
gen affective_polarization = (affect_inparty - affect_outparty)


* Congenial source (table E4)
reg outparty_voting i.D i.P if M==0, rob			
reg affect_inparty i.D i.P if M==0, rob	
reg affect_outparty i.D i.P if M==0, rob
reg affective_polarization i.D i.P if M==0, rob

* Uncongenial source (table E5)
reg outparty_voting i.D i.P if M==1, rob			
reg affect_inparty i.D i.P if M==1, rob				
reg affect_outparty i.D i.P if M==1, rob
reg affective_polarization i.D i.P if M==1, rob


**# App. F.3
use  "data_S3.dta", clear 						// Remember to update file directory ("INSERTPATH") in cd above

gen election = (pei-1)/4
gen affect_inparty = (inparty_affect/10)
gen affect_outparty = (outparty_affect/10)
gen affective_polarization = (affect_inparty - affect_outparty)

reg election i.D i.M i.P, rob
reg affect_inparty i.D i.M i.P, rob
reg affect_outparty i.D i.M i.P, rob
reg affective_polarization i.D i.M i.P, rob
reg outparty_voting i.D i.M i.P, rob
reg inparty_voting i.D i.M i.P, rob
reg independent_voting i.D i.M i.P, rob


**# App. G.3
use  "data_S3.dta", clear 						// Remember to update file directory ("INSERTPATH") in cd above

gen election = (pei-1)/4
gen affect_inparty = (inparty_affect/10)
gen affect_outparty = (outparty_affect/10)
gen affective_polarization = (affect_inparty - affect_outparty)

* Excluding inattentive respondents, congenial source (table G4)
reg affect_inparty i.D i.P if M==0 & attention!=0, rob 
reg inparty_voting i.D i.P if M==0 & attention!=0, rob
reg affective_polarization i.D i.P if M==0 & attention!=0, rob
reg affect_outparty i.D i.P if M==0 & attention!=0, rob
reg outparty_voting i.D i.P if M==0 & attention!=0, rob
reg independent_voting i.D i.P if M==0 & attention!=0, rob

* Excluding inattentive respondents, uncongenial source (table G5)
reg affect_inparty i.D i.P if M==1 & attention!=0, rob 
reg inparty_voting i.D i.P if M==1 & attention!=0, rob
reg affective_polarization i.D i.P if M==1 & attention!=0, rob
reg affect_outparty i.D i.P if M==1 & attention!=0, rob
reg outparty_voting i.D i.P if M==1 & attention!=0, rob
reg independent_voting i.D i.P if M==1 & attention!=0, rob


**# App. H.3
use  "data_S3.dta", clear 						// Remember to update file directory ("INSERTPATH") in cd above

gen election = (pei-1)/4
gen affect_inparty = (inparty_affect/10)
gen affect_outparty = (outparty_affect/10)
gen affective_polarization = (affect_inparty - affect_outparty)

* Excluding leaners - congenial source (table H4)
reg election i.D i.P if M == 0 & pid != 0 , rob
reg affect_inparty i.D i.P if M==0 & pid != 0 , rob
reg inparty_voting i.D i.P if M==0 & pid != 0 , rob
reg affective_polarization i.D i.P if M==0 & pid != 0 , rob
reg affect_outparty i.D i.P if M==0 & pid != 0 , rob
reg outparty_voting i.D i.P if M==0 & pid != 0 , rob
reg independent_voting i.D i.P if M==0 & pid != 0 , rob

* Excluding leaners - uncongenial source (table H5)
reg election i.D i.P if M == 1 & pid != 0 , rob
reg affect_inparty i.D i.P if M==1 & pid != 0 , rob 
reg inparty_voting i.D i.P if M==1 & pid != 0 , rob
reg affective_polarization i.D i.P if M==1 & pid != 0 , rob
reg affect_outparty i.D i.P if M==1 & pid != 0 , rob
reg outparty_voting i.D i.P if M==1 & pid != 0 , rob
reg independent_voting i.D i.P if M==1 & pid != 0 , rob


**# App. I
use  "data_S3.dta", clear 						// Remember to update file directory ("INSERTPATH") in cd above

gen election = (pei-1)/4
gen affect_inparty = (inparty_affect/10)
gen affect_outparty = (outparty_affect/10)
gen affective_polarization = (affect_inparty - affect_outparty)

* Make a series of identical treatment variables

gen D1 = D
gen D2 = D 
gen D3 = D
gen D4 = D
gen D5 = D

* Election believers: Run estimations for in-party sources and store results: 
eststo clear

eststo inp1: qui reg affect_inparty i.D i.P if M==0 & fraud_beliefs_d==0, rob 
eststo inp2: qui reg inparty_voting i.D1 i.P if M==0 & fraud_beliefs_d==0, rob
eststo inp3: qui reg affective_polarization i.D2 i.P if M==0 & fraud_beliefs_d==0, rob
eststo inp4: qui reg affect_outparty i.D3 i.P if M==0 & fraud_beliefs_d==0, rob
eststo inp5: qui reg outparty_voting i.D4 i.P if M==0 & fraud_beliefs_d==0, rob
eststo inp6: qui reg independent_voting i.D5 i.P if M==0 & fraud_beliefs_d==0, rob


* Run estimations for out-party sources and store results:
eststo outp1: qui reg affect_inparty i.D i.P if M==1 & fraud_beliefs_d==0, rob 
eststo outp2: qui reg inparty_voting i.D1 i.P if M==1 & fraud_beliefs_d==0, rob
eststo outp3: qui reg affective_polarization i.D2 i.P if M==1 & fraud_beliefs_d==0, rob
eststo outp4: qui reg affect_outparty i.D3 i.P if M==1 & fraud_beliefs_d==0, rob
eststo outp5: qui reg outparty_voting i.D4 i.P if M==1 & fraud_beliefs_d==0, rob
eststo outp6: qui reg independent_voting i.D5 i.P if M==1 & fraud_beliefs_d==0, rob

* Plot the findings:  
graph drop _all 

coefplot (inp1 inp2 inp3 inp4 inp5 inp6, label("In-Party Source") mcolor(black) mlabcolor(black) msymbol(O) msize(medlarge) ciopts(lcolor(black) recast(rspike))) ///
   (outp1 outp2 outp3 outp4 outp5 outp6, label("Out-Party Source") mcolor(black) mfcolor(white) msymbol(O) msize(medlarge) ciopts(lcolor(black) recast(rspike))) ///
   , drop(_cons 0.P 1.P) ///
   scale(1.3) ///
   xline(0, lcolor("146 214 213") lpattern(solid)) ///
   graphregion(fcolor(white)) ///
   plotregion(lcolor(gs10) lwidth(medium)) ///
   xlabel(-.3 -.15 0 .15, notick nogrid) ///
   xtitle("Treatment Effect", size(medium)) ///
   xscale(range(-.4/.2) lcolor(gs10%75) lwidth(vvthin)) ///
   ylabel(, nogrid) ///
   yscale(lcolor(gs10%75) lwidth(vvthin)) ///
   grid(none) ///
   coeflabels( ///
   1.D = "In-Party Affect" ///
   1.D1 = "Propensity to Vote In-Party" ///
   1.D2 = "Net In-Party Favorability" ///
   1.D3 = "Out-Party Affect" ///
   1.D4 = "Propensity to Vote Out-Party" ///
   1.D5 = "Propensity to Vote Independent", labsize(medsmall)) ///
   headings( ///
   1.D = "{bf: In-Party Support}" ///
   1.D3 = "{bf: Out-Party Support}", labsize(medsmall)) ///
   title("Election Believers", justification(center) box bexpand fcolor(gs12%50) lcolor(gs10) margin(small)) ///
   name(A, replace)

** Election deniers: Run estimations for out-party sources and store results:
eststo clear

eststo inp1: qui reg affect_inparty i.D i.P if M==0 & fraud_beliefs_d==1, rob 
eststo inp2: qui reg inparty_voting i.D1 i.P if M==0 & fraud_beliefs_d==1, rob
eststo inp3: qui reg affective_polarization i.D2 i.P if M==0 & fraud_beliefs_d==1, rob
eststo inp4: qui reg affect_outparty i.D3 i.P if M==0 & fraud_beliefs_d==1, rob
eststo inp5: qui reg outparty_voting i.D4 i.P if M==0 & fraud_beliefs_d==1, rob
eststo inp6: qui reg independent_voting i.D5 i.P if M==0 & fraud_beliefs_d==1, rob

eststo outp1: qui reg affect_inparty i.D i.P if M==1 & fraud_beliefs_d==1, rob 
eststo outp2: qui reg inparty_voting i.D1 i.P if M==1 & fraud_beliefs_d==1, rob
eststo outp3: qui reg affective_polarization i.D2 i.P if M==1 & fraud_beliefs_d==1, rob
eststo outp4: qui reg affect_outparty i.D3 i.P if M==1 & fraud_beliefs_d==1, rob
eststo outp5: qui reg outparty_voting i.D4 i.P if M==1 & fraud_beliefs_d==1, rob
eststo outp6: qui reg independent_voting i.D5 i.P if M==1 & fraud_beliefs_d==1, rob   
   
coefplot (inp1 inp2 inp3 inp4 inp5 inp6, label("In-Party Source") mcolor(black) mlabcolor(black) msymbol(O) msize(medlarge) ciopts(lcolor(black) recast(rspike))) ///
   (outp1 outp2 outp3 outp4 outp5 outp6, label("Out-Party Source") mcolor(black) mfcolor(white) msymbol(O) msize(medlarge) ciopts(lcolor(black) recast(rspike))) ///
   , drop(_cons 0.P 1.P) ///
   scale(1.3) ///
   xline(0, lcolor("146 214 213") lpattern(solid)) ///
   graphregion(fcolor(white)) ///
   plotregion(lcolor(gs10) lwidth(medium)) ///
   xlabel(-.3 -.15 0 .15, notick nogrid) ///
   xtitle("Treatment Effect", size(medium)) ///
   xscale(range(-.4/.2) lcolor(gs10%75) lwidth(vvthin)) ///
   ylabel(, nogrid) ///
   yscale(lcolor(gs10%75) lwidth(vvthin)) ///
   grid(none) ///
   coeflabels( ///
   1.D = "In-Party Affect" ///
   1.D1 = "Propensity to Vote In-Party" ///
   1.D2 = "Net In-Party Favorability" ///
   1.D3 = "Out-Party Affect" ///
   1.D4 = "Propensity to Vote Out-Party" ///
   1.D5 = "Propensity to Vote Independent", labsize(medsmall)) ///
   headings( ///
   1.D = "{bf: In-Party Support}" ///
   1.D3 = "{bf: Out-Party Support}", labsize(medsmall)) ///
   title("Election Deniers", justification(center) box bexpand fcolor(gs12%50) lcolor(gs10) margin(small)) ///
   name(B, replace)   
   
  
**# App. L 
use  "data_S3.dta", clear 						// Remember to update file directory ("INSERTPATH") in cd above

gen election = (pei-1)/4
gen affect_inparty = (inparty_affect/10)
gen affect_outparty = (outparty_affect/10)
gen affective_polarization = (affect_inparty - affect_outparty)

eststo clear
eststo m0: reg election i.D##i.M i.P, rob
eststo m1: reg affect_inparty i.D##i.M i.P, rob
eststo m2: reg inparty_voting i.D##i.M i.P, rob
eststo m3: reg affective_polarization i.D##i.M i.P, rob
eststo m4: reg affect_outparty i.D##i.M i.P, rob
eststo m5: reg outparty_voting i.D##i.M i.P, rob
eststo m6: reg independent_voting i.D##i.M i.P, rob

esttab m0 m1 m2 m3 m4 m5 m6 ///
   using "/Users/au448989/Downloads/L1.tex" ///
   , obslast gaps ar2 nonumbers nonotes se ///
   drop(0.D 0.M 0.P 0.D#0.M 0.D#1.M 1.D#0.M ) ///
   addnotes("\textit{Note:} Unstandardized OLS regression estimates. Robust standard errors in parentheses." ///
   "\sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\) (two-sided tests).") ///
    title("Conditional Treatment Effects (S3)") ///
	varlabels(1.D "Gerrymandering" 1.M "Out-Party Source" 1.D#1.M "Gerrym. $\times$ Out-P. Source" 1.P "Republican ID" _cons Constant)  ///
	mti("Election Beliefs" "In-Party Affect" "Vote In-Party" "Aff. Pol." "Out-Party Affect" "Vote Out-Party" "Vote Ind.") ///
	replace b(%7.2f) se(%7.2f)  


**# App. M
* Reset frames
frame reset

* Open data and set background scheme
use  "data_S3.dta", clear 						// Remember to update file directory ("INSERTPATH") in cd above
set scheme plotplain

gen election = (pei-1)/4
gen affect_inparty = (inparty_affect/10)
gen affect_outparty = (outparty_affect/10)
gen affective_polarization = (affect_inparty - affect_outparty)


qui reg inparty_voting i.D i.P i.M, rob
qui margins D
mat A = r(table)

qui reg outparty_voting i.D i.P i.M, rob
qui margins D
mat B = r(table)

qui reg independent_voting i.D i.P i.M, rob
qui margins D
mat C = r(table)

mat P = 0,0,.1,A[1,1],A[5,1],A[6,1]\		///
		1,0,.3,A[1,2],A[5,2],A[6,2]\	///
		0,1,.1,B[1,1],B[5,1],B[6,1]\		///
		1,1,.3,B[1,2],B[5,2],B[6,2]\	///
		0,2,.1,C[1,1],C[5,1],C[6,1]\		///
		1,2,.3,C[1,2],C[5,2],C[6,2]	
		

frame create plot1
cwf plot1		
svmat P
rename P1 condition
rename P2 outcome
rename P3 Xpos
rename P4 b
rename P5 ll
rename P6 ul	


tw ///
	(bar b Xpos if condition == 0, mlab(b) mlabformat(%5.2fc) mlabposition(12) mlabcolor(black) mlabgap(2) ///
	barw(.15) col(black) fcol(white) by(outcome, title("") note("") legend(off) rows(1))) ///
	(bar b Xpos if condition == 1, mlab(b) mlabformat(%5.2fc) mlabposition(12) mlabcolor(black) mlabgap(2) ///
	barw(.15) col(gs12) fcol(gs12) by(outcome)) ///
	(rspike ll ul Xpos, lcolor(black)) ///
	, xscale(range(0 .4) lc(none)) ///
	xlab(.1 "Control" .3 "Gerrymandering", notick nogrid labsize(small)) ///
	yscale(range(0 1) lc(none)) ylab(0 .2 .4 .6 .8 1, notick nogrid) ytit("Vote Share") yline(.5) ///
	xtit("Treatment Status") ///
	plotregion(lcolor(black) lwidth(medium)) ///
	name(S3_vote_share, replace)
	
graph display, ysize(4.5) xsize(10) scale(1.4)


**# App. N
* Reset frames
frame reset

* Open data and set background scheme
use  "data_S3.dta", clear 						// Remember to update file directory ("INSERTPATH") in cd above
set scheme plotplain

* make & rescale variables
gen affect_inparty = (inparty_affect/10)
gen affect_outparty = (outparty_affect/10)
gen affective_polarization = (affect_inparty - affect_outparty)
gen election = (pei-1)/4

frame rename default data


qui reg affect_inparty i.D i.P if M==0 & P == 0, rob		// M (congeniality: 0 = congenial, 1 = uncongenial) P (Party ID: 0 = Democrat, 1 = Republican)
mat B1 = r(table)
qui reg affect_inparty i.D i.P if M==0 & P == 1, rob
mat B2 = r(table)
qui reg affect_inparty i.D i.P if M==1 & P == 0, rob
mat B3 = r(table)
qui reg affect_inparty i.D i.P if M==1 & P == 1, rob
mat B4 = r(table)


qui reg affect_outparty i.D i.P if M==0 & P == 0, rob
mat C1 = r(table)
qui reg affect_outparty i.D i.P if M==0 & P == 1, rob
mat C2 = r(table)
qui reg affect_outparty i.D i.P if M==1 & P == 0, rob
mat C3 = r(table)
qui reg affect_outparty i.D i.P if M==1 & P == 1, rob
mat C4 = r(table)



qui reg affective_polarization i.D i.P if M==0 & P == 0, rob
mat D1 = r(table)
qui reg affective_polarization i.D i.P if M==0 & P == 1, rob
mat D2 = r(table)
qui reg affective_polarization i.D i.P if M==1 & P == 0, rob
mat D3 = r(table)
qui reg affective_polarization i.D i.P if M==1 & P == 1, rob
mat D4 = r(table)



mat H = 0,.81,B1[1,2],B1[5,2],B1[6,2],0\ 	///
		1,.79,B2[1,2],B2[5,2],B2[6,2],1\	///
		0,.76,C1[1,2],C1[5,2],C1[6,2],0\ 	///
		1,.74,C2[1,2],C2[5,2],C2[6,2],1\ 	///
		0,.71,D1[1,2],D1[5,2],D1[6,2],0\ 	///
		1,.69,D2[1,2],D2[5,2],D2[6,2],1
		
		
		
* make plot 
frame create plot1
cwf plot1		
svmat H
rename H1 pid
rename H2 Ypos
rename H3 b
rename H4 ll
rename H5 ul
rename H6 source					// 0 = congenial, 1 = uncongenial


tw ///
	(rspike ll ul Ypos if pid==0, horizontal lcolor("10 117 173")) ///
	(rspike ll ul Ypos if pid==1, horizontal lcolor("255 64 64")) ///
	(scatter Ypos b if pid==0, msym(O) mc("10 117 173") msize(med)) ///
	(scatter Ypos b if pid==1, msym(O) mc("255 64 64") msize(med)) ///
	,yscale(range(.69 .85) lc(none)) ytit("") ///
	ylab(.83 "{bf:Party Attachments}" .8 "In-Party Affect" .75 "Out-Party Affect" .7 "Affective Polarization", notick nogrid) ///
	xtit("Treatment Effect") xscale(range(-.2 .15) lc(none)) xlab(-.2 -.1 0 .1 .2, notick nogrid) xline(0) ///
	legend(off) plotregion(lcolor(black) lwidth(medium)) ///
	title("{bf:A} Congenial Source", size(medsmall) justification(left) pos(11)) ///
	name(S3_affect_pid_A, replace)
	
mat I = 0,.81,B3[1,2],B3[5,2],B3[6,2],0\ 	///
		1,.79,B4[1,2],B4[5,2],B4[6,2],1\	///
		0,.76,C3[1,2],C3[5,2],C3[6,2],0\ 	///
		1,.74,C4[1,2],C4[5,2],C4[6,2],1\ 	///
		0,.71,D3[1,2],D3[5,2],D3[6,2],0\ 	///
		1,.69,D4[1,2],D4[5,2],D4[6,2],1
		
* make plot 
frame create plot2
cwf plot2		
svmat I
rename I1 pid
rename I2 Ypos
rename I3 b
rename I4 ll
rename I5 ul
rename I6 source					// 0 = congenial, 1 = uncongenial	


tw ///
	(rspike ll ul Ypos if pid==0, horizontal lcolor("10 117 173")) ///
	(rspike ll ul Ypos if pid==1, horizontal lcolor("255 64 64")) ///
	(scatter Ypos b if pid==0, msym(O) mc("10 117 173") msize(med)) ///
	(scatter Ypos b if pid==1, msym(O) mc("255 64 64") msize(med)) ///
	,yscale(range(.69 .85) lc(none)) ytit("") ///
	ylab(none, notick nogrid) ///
	xtit("Treatment Effect") xscale(range(-.2 .15) lc(none)) xlab(-.2 -.1 0 .1 .2, notick nogrid) xline(0) ///
	legend(order(3 "Democrat" 4 "Republican" )) plotregion(lcolor(black) lwidth(medium)) ///
	title("{bf:B} Uncongenial Source", size(medsmall) justification(left) pos(11)) ///
	aspect(.55,place(w)) ///
	name(S3_affect_pid_B, replace)	
	
	

graph combine S3_affect_pid_A S3_affect_pid_B, rows(1) ycommon 
graph display, xsize(8) ysize(2.5) scale(2.5)

